package com.yogee.topseller.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.yogee.topseller.R;
import com.yogee.topseller.utils.GlideUtils;

import java.security.acl.NotOwnerException;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * @auathor ${XiaoJianghong}
 * @date 2017/7/13.
 */
public class OrderImgAdapter extends RecyclerView.Adapter<OrderImgAdapter.ItemHolder> {

    private Context context;
    private OnItemPhotoClickListener onItemPhotoClickListener;
    private List<String> data;

    public OrderImgAdapter(Context context) {
        this.context = context;
    }

    public void addData(List<String> data) {
        this.data = data;
        notifyDataSetChanged();
    }

    public void setOnItemPhotoClickListener(OnItemPhotoClickListener onItemPhotoClickListener) {
        this.onItemPhotoClickListener = onItemPhotoClickListener;
    }

    @Override
    public ItemHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_order_img, parent, false);
        return new ItemHolder(view);
    }

    @Override
    public void onBindViewHolder(ItemHolder holder, final int position) {
        GlideUtils.defultImage(context, data.get(position), holder.itemOrderIv);
        holder.itemOrderRl.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                onItemPhotoClickListener.onItemPhotoClick(position);
            }
        });
        TextView tv = holder.itemOrderTv;
        switch (position){
            case 0:
                tv.setText("打款凭证");
                break;
            case 1:
                tv.setText("身份证正面");
                break;
            case 2:
                tv.setText("身份证背面");
                break;
            case 3:
                tv.setText("银行卡正面");
                break;
            case 4:
                tv.setText("银行卡背面");
                break;
        }


    }

    @Override
    public int getItemCount() {
        return data == null ? 0 : data.size();
    }

    class ItemHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.item_order_iv)
        ImageView itemOrderIv;
        @BindView(R.id.item_order_rl)
        RelativeLayout itemOrderRl;
        @BindView(R.id.item_order_tv)
        TextView itemOrderTv;

        public ItemHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }

    public interface OnItemPhotoClickListener {
        void onItemPhotoClick(int pos);
    }
}
